//
//  ViewController.m
//  SoundPlayer
//
//  Created by iD Student on 7/9/13.
//  Copyright (c) 2013 iD Student. All rights reserved.
//

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>


@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"explosion" withExtension: @"mp3"];
    NSError * error;
    explosionSound = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: &error];
    if(error != nil)
    {
        //This happens when the sound cannot be loaded
        NSLog(@"Explosion sound could not be loaded!");
    }
    else{
        [explosionSound prepareToPlay];
    }
    url = [[NSBundle mainBundle] URLForResource:@"laser" withExtension: @"mp3"];
    error = nil;
    laserSound = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: &error];
    if(error != nil)
    {
        //This happens when the sound cannot be loaded
        NSLog(@"Explosion sound could not be loaded!");
    }
    else{
        [laserSound prepareToPlay];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [sound1 release];
    [sound2 release];
    [super dealloc];
}


- (IBAction)explosionSoundButton:(id)sender {
    if(explosionSound.isPlaying == true)
    {
        [explosionSound stop];
        [explosionSound setCurrentTime: 0.0];
        [explosionSound play];
        
    } else {
        [explosionSound play];
    }
}

- (IBAction)laserSoundButton:(id)sender {
    if(laserSound.isPlaying == true)
    {
        [laserSound stop];
        [laserSound setCurrentTime: 0.0];
        [laserSound play];
        
    } else {
        [laserSound play];
    }
}



@end
